<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ leftCount }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          @click="$emit('changeType', 'all')"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'no' }"
          @click="$emit('changeType', 'no')"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'yes' }"
          @click="$emit('changeType', 'yes')"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <!-- v-show绑定ifShow方法判断按钮是否显示 点击事件删除已完成事件 -->
    <button class="clear-completed" v-show="ifShow" @click="delFn">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
  },
  computed: {
    // 判断是否显示清除按钮
    ifShow() {
      return this.list.some((item) => item.isDone)
    },
    // 计算剩余数量
    leftCount() {
      return this.list.filter((item) => !item.isDone).length
    },
  },
  methods: {
    delFn() {
      this.$emit('del')
    },
  },
}
</script>
